package net.wenku8.reader.view

import android.annotation.SuppressLint
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.BottomAppBar
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.viewmodel.compose.viewModel
import net.wenku8.reader.ui.lite.LiteText
import net.wenku8.reader.ui.lite.iconMinSize
import net.wenku8.reader.ui.lite.liteInline
import net.wenku8.reader.ui.lite.onClick
import net.wenku8.reader.ui.theme.LiteBlue
import net.wenku8.reader.view.file.FileBookcase
import net.wenku8.reader.view.online.OnlineBookcase
import net.wenku8.reader.view.rank.RankList
import net.wenku8.reader.view.user.User


@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
@Composable
fun Home() {
    val homeViewModel = viewModel<HomeViewModel>()
    Scaffold(
        containerColor = Color.Transparent,
        bottomBar = {
            BottomAppBar(
                containerColor = Color.Transparent,
                contentColor = MaterialTheme.colorScheme.primary,
                modifier = Modifier.height(80.dp)
            ) {
                Row{
                    val modifier = Modifier
                        .liteInline()
                        .background(Color.Transparent)
                        .height(80.dp)
                        .weight(1f)
                    PageTab.entries.forEach { tab ->
                        Column(
                            modifier = modifier.onClick {
                                homeViewModel.index = tab
                            },
                            horizontalAlignment = Alignment.CenterHorizontally
                        ) {
                            val color = if(tab == homeViewModel.index) LiteBlue else Color.Black
                            Icon(imageVector = tab.icon, contentDescription = "tab", tint = color, modifier = Modifier.iconMinSize())
                            LiteText(text = tab.label, fontSize = 12.sp, color = color )
                        }
                    }
                }
            }
        }
    ) {
        Surface(
            modifier = Modifier.padding(bottom = it.calculateBottomPadding())
        ){
            when(homeViewModel.index){
                PageTab.BOOKCASE -> OnlineBookcase()
                PageTab.FILE -> FileBookcase()
                PageTab.SEARCH -> RankList()
                PageTab.USER -> User()
            }

        }
    }
}
